using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameStateManagement;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Graphics;
using GameStateManagementSample.QuickMath;
namespace GameStateManagementSample.Screens
{
    class Screen_Intro : GameScreen
    {
        #region Fields
        ContentManager m_Content;
        InputAction pauseAction;

        Texture2D m_TexBack;
        SpriteFont m_Font;
        #endregion
        #region Initialization
        public Screen_Intro()
        {
            TransitionOnTime = TimeSpan.FromSeconds(1.0f);
            TransitionOffTime = TimeSpan.FromSeconds(1.0f);
            pauseAction = new InputAction(
                new Buttons[] { Buttons.Start, Buttons.Back },
                new Keys[] { Keys.Escape },
                true);
            
        }
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (m_Content == null)
                {
                    m_Content = new ContentManager(ScreenManager.Game.Services, "Content");
                    ScreenManager.Game.ResetElapsedTime();
                    m_TexBack = m_Content.Load<Texture2D>(@"Image/Intro");                  
                    m_Font = m_Content.Load<SpriteFont>("gamefont");
                }
            }
        }
        public override void Deactivate()
        {
            base.Deactivate();
        }
        public override void Unload()
        {
            base.Unload();
        }
        #endregion
        #region Update and Draw
        protected virtual void OnCancel()
        {

        }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);

            if (!otherScreenHasFocus)
            {

            }
        }
        public override void HandleInput(Microsoft.Xna.Framework.GameTime gameTime, InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            PlayerIndex player;
            if (pauseAction.Evaluate(input, ControllingPlayer, out player))
            {
                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    screen.ExitScreen();
                }
                ScreenManager.AddScreen(new Screen_Menu(), null);
            }
            TouchCollection touches = input.TouchState;

            foreach (TouchLocation touch in touches)
            {
                if (touch.State == TouchLocationState.Pressed)
                {
                }
            }
        }

       
        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            Vector2 pos = new Vector2((TransitionPosition) * 800.0f, 0);
            spriteBatch.Begin();
            spriteBatch.Draw(m_TexBack, Vector2.Zero +pos, Color.White);
            
            spriteBatch.End();
        }
        #endregion
    }
}
